package com.ericsson.eritask.service.impl;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ericsson.eritask.dao.CommentDAO;
import com.ericsson.eritask.domain.Comment;
import com.ericsson.eritask.domain.CommentDocument;
import com.ericsson.eritask.dto.CommentsDTO;
import com.ericsson.eritask.service.CommentService;

@Service
public class CommentServiceImpl implements CommentService{


	@Autowired
	CommentDAO commentDao;

	@Override
	public void insertComment(CommentsDTO commentDto) {
		Comment comment = new Comment();
		comment.setDocId(commentDto.getDocId());
		//comment.setUser(commentDto.getSignum());
		comment.setCommentdate(commentDto.getCommentdate());
		commentDao.insertComment(comment);

	}

	@Override
	public List<String> insertDocumentFiles(List<InputStream> files, String fileName) {

		String fileId = null;

		List<String> fileIds = new ArrayList<String>();
		if(files.size() > 0){
			for(InputStream file : files){

				fileId = commentDao.insertCommentFile(file, fileName);
				System.out.println("fileId in insertDocumentFiles():"+fileId);
				fileIds.add(fileId);
			}

		}


		return fileIds;
	}

	@Override
	public String inserDocument(List<String> fileIds, String text) {

		System.out.println("fieldId:::"+fileIds);
		CommentDocument cdoc = new CommentDocument();
		cdoc.setCommentText(text);
		cdoc.setFilesId(fileIds);
		commentDao.insertDocument(cdoc);
		System.out.println("cdoc id"+cdoc.getDocId());

		return cdoc.getDocId();
	}



}
